package imnu.th.tongbu01;

/**
 * @author: lys
 * @类名: Bank
 * @Title:
 * @date: 2020/7/22
 **/
public class Bank {
    private int account = 100;
    //取钱
    public synchronized int getMonet(int order){
        System.out.println("尊敬的"+Thread.currentThread().getName()+
            "用户，您余额为"+account+"元。");
        if (account >= order){

            System.out.println("系统正在处理，请稍等。。。");
            try {
                Thread.sleep((long) (Math.random()*2000+600));
            } catch (Exception e) {
                e.printStackTrace();
            }

            account -= order;
            System.out.println("尊敬的"+Thread.currentThread().getName()+
                    "用户，您本次的取款金额为"+order+"元,当前用户余额为"+account+"元。");
            System.out.println();
            return account;
        } else {
            System.out.println("对不起"+Thread.currentThread().getName()+",您的余额不足。。。");
            return 0;
        }
    }

    //咨询业务
    public synchronized void ask(){
        System.out.println(Thread.currentThread().getName()+"正在咨询，请稍后。。。");
        try {
            Thread.sleep((long) (Math.random()*2000+600));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"业务咨询完毕。");
        System.out.println();
    }
}
